define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'terminal_actvie_stands/index' + location.search,
                    // add_url: 'terminal_actvie_stands/add',
                    edit_url: 'terminal_actvie_stands/edit',
                    // del_url: 'terminal_actvie_stands/del',
                    multi_url: 'terminal_actvie_stands/multi',
                    import_url: 'terminal_actvie_stands/import',
                    table: 'terminal_actvie_stands',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), operate: false },
                        { field: 'name', title: __('客户') },
                        { field: 'proname', title: __('Proid'), operate: false },
                        { field: 'sn', title: __('Sn'), operate: 'LIKE' },
                        { field: 'termDays', title: __('Termdays'), operate: false },
                        { field: 'bind_times', title: __('Bind_times'), operate: false },
                        { field: 'end_times', title: __('End_times'), operate: false },
                        { field: 'stands_money', title: __('Stands_money'), operate: 'BETWEEN', operate: false },
                        { field: 'money', title: __('Money'), operate: 'BETWEEN', operate: false },
                        { field: 'process', title: __('Process'), searchList: { "1": __('Process 1'), "2": __('Process 2') }, formatter: Table.api.formatter.normal, operate: false },
                        { field: 'process_time', title: __('Process_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, operate: false },
                        { field: 'stands_typs', title: __('达标类型'), searchList: { "1": __('Stands_typs 1'), "2": __('Stands_typs 2') }, formatter: Table.api.formatter.normal, operate: false },
                        { field: 'exc_type', title: __('Exc_type'), searchList: { "1": __('Exc_type 1'), "2": __('Exc_type 2') }, formatter: Table.api.formatter.normal, operate: false },
                        { field: 'status', title: __('Status'), searchList: { "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status, operate: false },
                        { field: 'create_time', title: __('Create_time'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, operate: false },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'qrcode',
                                title: __('一键拨号'),
                                // text: __('接收'),
                                icon: 'fa fa-phone-square',
                                classname: 'btn btn-primary btn-xs btn-detail btn-dialog',
                                url: 'Machine/qr',
                                extend: 'data-area=\'["450px", "450px"]\''
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});